package cwinsor.com.leaf_raking;

import java.awt.image.ColorModel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;


public abstract class TableModelSummary extends TableModelBase {

	/*
	 * the table is as follows:
	 *
	 *0 Happiness       150                    Happiness           140
	 *1 Number On Team    1   3 3 3 3 3 3 3 3  Number On Team        1     3 3 4 2 2 2 2 2
	 *2 Number On Team    2   3 3 3 3 3 3 3 3  Number On Team        2     3 3 4 2 2 2 2 2
	 *3 Number On Team    3   3 3 3 2 3 3 3 3  Number On Team        3     3 3 4 2 2 2 2 2
	 *4 Number On Team    4   3 3 3 3 3 3 3 3  Number On Team        4     3 3 4 2 2 2 2 2
	 *5 Number On Team    5   3 3 3 3 3 3 3 3  Number On Team        5     3 3 4 2 2 2 2 2
	 *6 Number On Team    6   3 3 3 3 3 3 3 3  Number On Team        6     3 3 4 2 2 2 2 2
	 *7 Number On Team    7   3 3 3 3 3 3 3 3  Number On Team        7     3 3 4 2 2 2 2 2
	 *8 Number On Team    8   3 3 3 3 3 3 3 3  Number On Team        8     3 3 4 2 2 2 2 2
	 */


	TableModelData mainTable;

	/**
	 * constructor
	 */
	public TableModelSummary() {
	}	

	/*
	 * set reference to the main table
	 */
	public void setReferenceToMainTable(TableModelData mainTable) {
		this.mainTable = mainTable;

		// set the row count
		setRowCount(1 + TeamNumber.TEAMS_NO_U.size());
		Msg.note(dS + ": ZONA - TEAMS_NO_U.size() = " + TeamNumber.TEAMS_NO_U.size());
		setColumnCount(mainTable.getColumnCount());

		// initialize data
		for (int row=0; row<getRowCount(); row++) {
			for (int col=0; col<getColumnCount(); col++) {
				this.setValueAt(" ", row, col);
			}
		}
	}		

	/* 
	 * getValueAt
	 */
	public Object getValueAt(int row, int col) {
		if (row == 0) {
			if (mainTable.colIsTotalHappinessCurrent(col)) { return mainTable.reductionTotalHappinessCurrent(); }
			if (mainTable.colIsTotalHappinessProposed(col)) { return mainTable.reductionTotalHappinessProposed(); }
		}
		// row 2..n wants the count per team
		// if the count != 3 add a "<" to point it out
		if (row >= 1) {
			if (mainTable.colIsAvailTotalChange(col)) { return TeamNumber.integerToTeam(row).toString(); }
			TeamNumber teamNumber = TeamNumber.integerToTeam(row);
			// annotate
			if (mainTable.colIsAssignmentCurrent(col)) {
				WorkShift workShift = mainTable.colToShift(col);
				Integer tempI = mainTable.reductionAssignmentCurrentCount(workShift,teamNumber);
				String tempS = new String(tempI.toString() + ((tempI.equals(3)) ? "" : "*"));
				return tempS;
			}
			// annotate
			if (mainTable.colIsAssignmentProposed(col)) { 
				WorkShift workShift = mainTable.colToShift(col);
				Integer tempI = mainTable.reductionAssignmentProposedCount(workShift,teamNumber);
				String tempS = new String(tempI.toString() + ((tempI.equals(3)) ? "" : "*"));
				return tempS;
			}
		}
		// otherwise return a blank
		return " ";	
	}

	// debug
	String dS = this.getClass().getSimpleName();
	Integer dL = new Integer(1);
}